package com.lxy.allappinfo;

import java.util.List;

import android.content.Intent;
import android.content.pm.PackageInfo;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class MyFragment extends Fragment {
	
	private ListView listview;
	private MyAdapter adapter;
	private List<PackageInfo> packageInfo;
	
	
	public MyFragment(List<PackageInfo> packageInfo){
		this.packageInfo=packageInfo;
	}
	
	public static MyFragment getFragment(List<PackageInfo> packageInfo){
		return new MyFragment(packageInfo);
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		adapter=new MyAdapter(getActivity());
	}

	


	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		View view=inflater.inflate(R.layout.fragment_layout, null);
		listview=(ListView) view.findViewById(R.id.listview);
		listview.setAdapter(adapter);
		adapter.setList(packageInfo);
		listview.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View view, int position,
                    long arg3) {
				Intent intent=new Intent(getActivity(),DetailInfoActivity.class);
				Bundle bundle=new Bundle();
				bundle.putParcelable("pinfo", (PackageInfo)adapter.getItem(position));
				intent.putExtras(bundle);
				getActivity().startActivity(intent);
			}
		});
		return view;
	}
	
}
